package com.nullpointer.xchat.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.nullpointer.xchat.R;
import com.nullpointer.xchat.utils.Common;

public class EmoticonAdapter extends BaseAdapter {

	Context context;
	LayoutInflater inflater;

	public EmoticonAdapter(Context context) {
		this.context = context;
		inflater = (LayoutInflater) this.context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return Common.emoticons.length;
	}

	@Override
	public Object getItem(int position) {
		return Common.emoticons[position];
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		ViewHolder vh;
		if (convertView == null) {
			vh = new ViewHolder();
			convertView = inflater.inflate(R.layout.item_gv_emoticon, null);
			vh.ivEmoticon = (ImageView) convertView
					.findViewById(R.id.iv_emoticon);
			convertView.setTag(vh);
		} else {
			vh = (ViewHolder) convertView.getTag();
		}
		vh.ivEmoticon.setBackgroundColor(Color.TRANSPARENT);
		vh.ivEmoticon.setImageResource(Common.emoticons[position]);
		// AQuery aq = new AQuery(convertView);
		// aq.id(vh.ivEmoticon).image(Common.emoticons[position], true, true,
		// 36, 0);
		// Picasso.with(context).load(Common.emoticons[position]).resize(50, 50)
		// .into(vh.ivEmoticon);
		// vh.ivEmoticon.setOnClickListener(new OnClickListener() {
		//
		// @Override
		// public void onClick(View v) {
		// if (listener != null) {
		// listener.onClick(position);
		// }
		// }
		// });
		return convertView;
	}

	class ViewHolder {
		ImageView ivEmoticon;
	}
}
